/*
	This is what is left of my timer module. This is what I was going to use to make timers before the 1st player connects.
	After the GMOD 11 update the think hook was changed so it only runs after the 1st player connects. I then rewrote ptimer to use groups as was the plan with the original.
*/

//Globals we need
local table = table
local pairs = pairs
local unpack = unpack
local Msg = Msg
local string = string
local concommand = concommand
local timer = timer

module("ptimer")
local PTimers = {}

function Add(strID, intInterval, intRep, fnCallback, ...)
	return Add2(strID, "COMMON", intInterval, intRep, fnCallback, unpack(arg))
end

Create = Add

function Add2(strID, strGroup, intInterval, intRep, fnCallback, ...)
	if PTimers[strGroup] == nil then PTimers[strGroup] = {} end
	PTimers[strGroup][strID] = true
	return timer.Create(strID, intInterval, intRep, fnCallback, unpack(arg))
end

function Remove(strID, strGroup)
	strGroup = strGroup or "COMMON"
	PTimers[strGroup][strID] = nil
	timer.Remove(strID)
end

function Simple(intInterval, fnCallback, ...)
	return timer.Simple(intInterval, fnCallback, unpack(arg))
end

function IsTimer(strID)
	return timer.IsTimer(strID)
end

function IsGroup(strGroup)
	strGroup = strGroup or "COMMON"
	strGroup = string.upper(strGroup)
	
	if PTimers[strGroup] then
		return true
	else
		return false
	end
end

function Pause(strID)
	return timer.Pause(strID)
end

function UnPause(strID)
	return timer.UnPause(strID)
end

function Toggle(strID)
	return timer.Toggle(strID)
end

function Start(strID)
	return timer.Start(strID)
end

function Stop(strID)
	return timer.Stop(strID)
end

function RemoveGroup(strGroup)
	if PTimers[strGroup] == nil then return end
	for k, _ in pairs(PTimers[strGroup]) do
		Remove(k, strGroup)
	end
	PTimers[strGroup] = nil
end

function PauseGroup(strGroup)
	if PTimers[strGroup] == nil then return end
	for k, _ in pairs(PTimers[strGroup]) do
		if IsTimer(k) then
			Pause(k, strGroup)
		else
			PTimers[strGroup][k] = nil
		end
	end
end

function UnPauseGroup(strGroup)
	if PTimers[strGroup] == nil then return end
	for k, _ in pairs(PTimers[strGroup]) do
		if IsTimer(k) then
			UnPause(k, strGroup)
		else
			PTimers[strGroup][k] = nil
		end
	end
end

function StopGroup(strGroup)
	if PTimers[strGroup] == nil then return end
	for k, _ in pairs(PTimers[strGroup]) do
		if IsTimer(k) then
			Stop(k, strGroup)
		else
			PTimers[strGroup][k] = nil
		end
	end
end

function StartGroup(strGroup)
	if PTimers[strGroup] == nil then return end
	for k, _ in pairs(PTimers[strGroup]) do
		if IsTimer(k) then
			Start(k, strGroup)
		else
			PTimers[strGroup][k] = nil
		end
	end
end



